﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace RUMFBApp.Models
{
    public class RUMFBAppRepository
    {
        private RUMFBAppDataContext db = new RUMFBAppDataContext();
        //Gets all users
        public IQueryable<User> GetAllUsers()
        {
            return db.Users;
        }
        //Find the User by FacebookId
        public User FindUser(int FacebookId)
        {
            return db.Users.SingleOrDefault(u => u.FacebookId == FacebookId);
        }
        //Get User by UserId
        public User GetUser(int UserId)
        {
            return db.Users.SingleOrDefault(u => u.UserId == UserId);
        }
        //Gets all buildings
        public IQueryable<Building> GetAllBuildings()
        {
            return db.Buildings;
        }
        //Finds all the buildings in CategoryId
        public IQueryable<Building> FindBuildingsByCategory(int CategoryId)
        {
            return from building in db.Buildings
                   where building.BuildingCategoryId == CategoryId
                   orderby building.Name
                   select building;
        }
        //Finds a building by ShortName
        public Building FindBuildingByShortName(String ShortName)
        {
            return db.Buildings.SingleOrDefault(b => b.ShortName == ShortName);
        }




    }
}